package com.zhisheng.gufei.produce.service.impl;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Service;

import com.zhisheng.core.page.Page;
import com.zhisheng.core.security.support.SecurityUserHolder;
import com.zhisheng.core.service.impl.BaseServiceImpl;
import com.zhisheng.gufei.city.entity.JsonCity;
import com.zhisheng.gufei.produce.dao.DeclarationDao;
import com.zhisheng.gufei.produce.entity.Declaration;
import com.zhisheng.gufei.produce.entity.GrabageStat;
import com.zhisheng.gufei.produce.entity.MainProduce;
import com.zhisheng.gufei.produce.service.DeclarationService;


/**
 * @author xgye
 *
 */
@Service("declarationService")
public class DeclarationServiceImpl extends BaseServiceImpl<Declaration, Integer, DeclarationDao> 
                                                    implements DeclarationService {
	
	public void setDeclarationDao(DeclarationDao declarationDao) {
		this.entityDao = declarationDao;
	}

	public void saveDeclaration(Declaration dec) {
		this.entityDao.saveDeclaration(dec);
	}
	
	/*
	 * 
	 * 获得待审列表
	 */
	@Override
	public void getAuditPage(Page<Declaration> page,Integer audit) {
		this.entityDao.getAuditPage(page, audit);
	}
	
	/*
	 * 
	 * 更具用户名 获得已审列表
	 */
	@Override
	public void getCheckedPage(Page<Declaration> page) {
		this.entityDao.getCheckedPage(page, SecurityUserHolder.getCurrentUser().getName());
	}
	
    public List<MainProduce> getInitialProduceList(Integer type) {
        List<MainProduce> produceList = new ArrayList<MainProduce>();
        for (int i = 0; i < 3; i++) {
            MainProduce mp = new MainProduce();
            
            mp.setType(type);
            
            produceList.add(mp);
        }
        return produceList;
    }

    public String populateToString(List<MainProduce> produceList) {
        return JSONArray.fromObject(produceList).toString().replace("\\r\\n", "");
    }
    
    
    public String p(List<GrabageStat> list) {
        return JSONArray.fromObject(list).toString().replace("\\r\\n", "");
    }
    
    public static void main(String[] args) {
        List<GrabageStat> s = new ArrayList<GrabageStat>();
        
        GrabageStat stat = new GrabageStat();
        stat.setAllStockAmount(42f);
        stat.setDisposeAmount(23f);
        stat.setDisposePast(232f);
        stat.setEmissionAmount(323f);
        stat.setUseAmount(23f);
        stat.setStockAmount(323f);
        stat.setProductAmount(323f);
        JsonCity city = new  JsonCity();
        city.setId(2);
        city.setCityName("绵阳市");
        stat.setCity(city);
        
        
        s.add(stat);
        
        DeclarationServiceImpl ser = new DeclarationServiceImpl();
        System.out.println(ser.p(s));
    }
    
}
